package com.chen.controller;

import com.chen.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
public class AjaxController {
    @RequestMapping("/test")
    public String test(){
        return "come on";
    }
    @RequestMapping("/a1")
    public void a1(String name, HttpServletResponse response) throws IOException {
        System.out.println("name=>"+name);
        if ("chen".equals(name)){
            response.getWriter().print("true");
        }else{
            response.getWriter().print("false");
        }
    }

    @RequestMapping("/a2")
    public List<User> a2(){
        List<User> userlist = new ArrayList<User>();
//         添加数据
        userlist.add(new User("java",14,"男"));
        userlist.add(new User("python",25,"女"));
        userlist.add(new User("go",41,"男"));

        return userlist;
    }


    @RequestMapping("/pdym")
    public String a3(String name,String pwd){
        String msg="";
        if (name!=null){
            if ("admin".equals(name)){
                msg="ok";
            }else{
                msg="用户名错误";
            }
        }
        if (pwd!=null){
            if ("123456".equals(pwd)){
                msg="ok";
            }else{
                msg="密码错误";
            }
        }
        return msg;
    }


}
